//
//  ExploreStoryTableViewCell.m
//  EDPS
//
//  Created by 张维扬 on 15/11/26.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "ExploreStoryTableViewCell.h"
#import "ExploreCollectionViewCell.h"
#import "Masonry.h"
@interface ExploreStoryTableViewCell ()
@property (nonatomic, retain) UICollectionView *collectionView;
@end

@implementation ExploreStoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UICollectionViewFlowLayout * Layout = [[UICollectionViewFlowLayout alloc] init];
        Layout.itemSize = CGSizeMake((ScreenWidth - 30) / 2, (ScreenWidth - 30) / 2);
        Layout.minimumLineSpacing = 10;
        Layout.minimumInteritemSpacing = 10;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:Layout];
        self.collectionView.backgroundColor = RGBA(253, 244, 233, 1);
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [self.collectionView registerClass:[ExploreCollectionViewCell class] forCellWithReuseIdentifier:@"collectionViewCell"];
        [self.contentView addSubview:self.collectionView];
    }
    return self;
}
#pragma mark - 协议方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ExploreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell" forIndexPath:indexPath];
    cell.model = self.story_dataArr[indexPath.row];
    cell.imgName_Model = self.imgName_dataArr[indexPath.row];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.story_dataArr.count;
}
// collectionView代理方法
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
{
    self.collectionView.dataSource = dataSource;
}
- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
{
    self.collectionView.delegate = delegate;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.left.mas_equalTo(self.contentView.mas_left).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
    }];
}
- (void)setStory_dataArr:(NSArray *)story_dataArr
{
    if (_story_dataArr != story_dataArr) {
        _story_dataArr = story_dataArr;
    }
    [self.collectionView reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
